<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<link rel="stylesheet" type="text/css" href="main.css" />
<title>Insert title here</title>
<script type="text/javascript">
	function submitForm(form, result) {
		var barcode = document.forms[form].elements["barcode"].value;
		var userId = document.forms[form].elements["userId"].value;
		var xmlHttp = new XMLHttpRequest();
		xmlHttp.open("GET", "issue?action=issue&userId=" + userId + "&barcode="
				+ barcode, false);
		xmlHttp.send();
		var text = xmlHttp.responseText;
		document.getElementById(result).innerHTML = text;
	}
</script>
</head>
<body>
	<%@include file="header.jsp"%>
	<article> <s:set name="jreservations" value="reservations"
		scope="request" /> <c:choose>
		<c:when test="${empty jreservations}">
			There are no reservations found!<br />
		</c:when>
		<c:otherwise>
			Current reservations!<br />
			<table>
				<tr>
					<th>Book</th>
					<th>Requester</th>
					<th>Request Date</th>
					<th>Available</th>
					<th>Action</th>
					<th>Result</th>
				</tr>
				<c:forEach var="item" items="${jreservations}"
					varStatus="rowCounter">
					<tr>
						<td><a href="bookDetails?bookId">${item.bookName}</a></td>
						<td>${item.requestor}</td>
						<td>${item.reserveDate}</td>
						<td>${item.available}</td>
						<td>
							<form id="form${rowCounter.count}" action="issue">
								<input type="text" name="barcode" /> <input type="hidden"
									name="userId" value="${item.userId}" />
							</form>
							<button type="button"
								onclick='submitForm("form${rowCounter.count}", "result${rowCounter.count}")'>Issue</button>
						</td>
						<td><p id="result${rowCounter.count}"></p></td>
					</tr>
				</c:forEach>
			</table>
		</c:otherwise>
	</c:choose> </article>
	<%@include file="footer.jsp"%>
</body>
</html>